<template>
  <transition>
    <div class="xtx-message" v-show="visible" :style="style">
      <span class="iconfont" :class="icon"></span>
      <span class="text">{{ message }}</span>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'xtx-message',
  data () {
    return {
      message: '',
      type: 'info',
      style: {},
      icon: {},
      visible: false
    }
  },
  created () {
    switch (this.type) {
      case 'info':
        this.style.color = '#909399'
        this.style.backgroundColor = 'rgb(236, 245, 255)'
        this.style.borderColor = 'rgb(217, 236, 255)'
        this.icon = { 'icon-warning': true }
        break
      case 'error':
        this.style.color = '#F56C6C'
        this.style.backgroundColor = 'rgb(254, 240, 240)'
        this.style.borderColor = 'rgb(253, 226, 226)'
        this.icon = { 'icon-shanchu': true }
        break
      case 'success':
        this.style.color = '#67C23A'
        this.style.backgroundColor = 'rgb(240, 249, 235)'
        this.style.borderColor = 'rgb(225, 243, 216)'
        this.icon = { 'icon-queren2': true }
        break
      case 'warn':
        this.style.color = '#E6A23C'
        this.style.backgroundColor = 'rgb(253, 246, 236)'
        this.style.borderColor = 'rgb(250, 236, 216)'
        this.icon = { 'icon-warning': true }
        break
    }
  },
  methods: {
    open () {
      this.visible = true
    }
  }
}
</script>

<style scoped lang='less'>
.v-enter,
.v-leave-to {
  transform: translateY(-100%);
  opacity: 0;
}
.v-enter-active,
.v-leave-active{
  transition: all .5s;
}
.xtx-message {
  width: 300px;
  height: 50px;
  line-height: 50px;
  position: fixed;
  top: 25px;
  left: 50%;
  margin-left: -150px;
  border-radius: 4px;
  border: 1px solid #fff;
  text-align: center;
  z-index: 9999;
  .iconfont {
    vertical-align: middle;
    position: relative;
    top: -1px;
    &::before {
      font-size: 18px;
    }
  }
  .text {
    font-size: 16px;
    vertical-align: middle;
    margin-left: 5px;
    padding-right: 18px;
  }
}
</style>
